import { FormSchema } from '@/components/Form';
import { getAreaTree } from '@/api/common/index';

export const addresSchemas: FormSchema[] = [
  // {
  //   field: 'f1',
  //   component: 'InputTextArea',
  //   label: '',
  //   required: true,

  //   colProps: {
  //     span: 20,
  //     offset: 2,
  //   },
  //   componentProps: {
  //     // 智能识别，粘贴信息，自动拆分仓库名称、电话和地址

  //     // 示例：金小金，金发供应链管理有限公司，黄埔仓，139********，广东省广州市黄埔区科学城科丰路33号
  //     placeholder:
  //       '智能识别，粘贴信息，自动拆分仓库名称、电话和地址 示例：    金小金，金发供应链管理有限公司，黄埔仓，139********，广东省广州市黄埔区科学城科丰路33号',
  //   },
  // },
  {
    field: 'companyName',
    component: 'Input',
    label: '企业名称',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'consigneeWarehouse',
    component: 'Input',
    label: '仓库名称',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'consigneeName',
    component: 'Input',
    label: '联系人',
    required: false,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'consigneePhone',
    component: 'Input',
    label: '联系电话',
    required: false,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'area1',
    component: 'ApiCascader',
    label: '仓库地址',
    colProps: {
      span: 8,
      offset: 2,
    },
    componentProps: ({ formModel }) => {
      return {
        showSearch: true,
        placeholder: '请选择',
        api: getAreaTree,
        labelField: 'areaName',
        valueField: 'areaCode',
        displayRenderArray: formModel.area1,
        onChange: (e, s, g, q) => {
          formModel.consigneeAreaCode = e[e.length - 1];
          formModel.area1 = [];
          // 判断省
          if (s) {
            formModel.consigneeProvince = s.label;
            formModel.area1[0] = s.label;
          } else {
            formModel.consigneeProvince = '';
            formModel.area1 = e;
          }
          // 判断市

          if (g) {
            formModel.consigneeCity = g.label;
            formModel.area1[1] = g.label;
          } else {
            formModel.consigneeCity = '';
            formModel.area1 = e;
          }
          // 判断区
          if (q) {
            formModel.consigneeArea = q.label;
            formModel.area1[2] = q.label;
          } else {
            formModel.consigneeArea = '';
            formModel.area1 = e;
          }
        },
      };
    },
    required: true,
  },
  {
    field: 'consigneeAddress',
    component: 'Input',
    label: '详细地址',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'consigneeProvince',
    component: 'Input',
    show: false,
    label: '省',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'consigneeCity',
    component: 'Input',
    show: false,
    label: '市',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'consigneeArea',
    component: 'Input',
    show: false,
    label: '区',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'consigneeAreaCode',
    component: 'Input',
    show: false,
    label: '编码',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
];

export const customerSchemas: FormSchema[] = [
  // {
  //   field: 'f1',
  //   component: 'InputTextArea',
  //   label: '',
  //   required: true,

  //   colProps: {
  //     span: 20,
  //     offset: 2,
  //   },
  //   componentProps: {
  //     // 智能识别，粘贴信息，自动拆分仓库名称、电话和地址

  //     // 示例：金小金，金发供应链管理有限公司，黄埔仓，139********，广东省广州市黄埔区科学城科丰路33号
  //     placeholder:
  //       '智能识别，粘贴信息，自动拆分仓库名称、电话和地址 示例：    金小金，金发供应链管理有限公司，黄埔仓，139********，广东省广州市黄埔区科学城科丰路33号',
  //   },
  // },
  {
    field: 'receiverCompany',
    component: 'Input',
    label: '客户名称',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'receiverName',
    component: 'Input',
    label: '联系人',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'receiverPhone',
    component: 'Input',
    label: '联系电话',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'area',
    component: 'ApiCascader',
    label: '收货地址',
    colProps: {
      span: 8,
      offset: 2,
    },
    componentProps: ({ formModel }) => {
      return {
        showSearch: true,
        placeholder: '请选择',
        api: getAreaTree,
        labelField: 'areaName',
        valueField: 'areaCode',
        displayRenderArray: formModel.area,
        onChange: (e, s, g, q) => {
          console.log(e, s, g, q);
          formModel.receiverAreaCode = e[e.length - 1];
          formModel.area = [];
          // 判断省
          if (s) {
            formModel.receiverProvince = s.label;
            formModel.area[0] = s.label;
          } else {
            formModel.receiverProvince = '';
            formModel.area = e;
          }
          // 判断市

          if (g) {
            formModel.receiverCity = g.label;
            formModel.area[1] = g.label;
          } else {
            formModel.receiverCity = '';
            formModel.area = e;
          }

          // 判断区
          if (q) {
            formModel.receiverArea = q.label;
            formModel.area[2] = q.label;
          } else {
            formModel.receiverArea = '';
            formModel.area = e;
          }
        },
      };
    },
    required: true,
  },
  {
    field: 'receiverAddress',
    component: 'Input',
    label: '详细地址',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'receiverProvince',
    component: 'Input',
    show: false,
    label: '省',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'receiverCity',
    component: 'Input',
    show: false,
    label: '市',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'receiverArea',
    component: 'Input',
    show: false,
    label: '区',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
  {
    field: 'receiverAreaCode',
    component: 'Input',
    show: false,
    label: '编码',
    colProps: {
      span: 8,
      offset: 2,
    },
    required: true,
  },
];

export const tableColumns: FormSchema[] = [
  {
    field: 'materialId',
    component: 'Input',
    label: '物料编码',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'productBrandId',
    component: 'Input',
    label: '物料牌号',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'goodsName',
    component: 'Input',
    label: '物料名称',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'goodsPack',
    component: 'Input',
    label: '包装规格',
    required: true,
    colProps: {
      span: 8,
      offset: 2,
    },
  },
  {
    field: 'volume',
    component: 'Input',
    label: '体积',
    colProps: {
      span: 8,
      offset: 2,
    },
  },
];
